$().ready(function(){
	
	$baseUrl = $("#baseUrl").text();
	
	$("#available, #letout, #sold").click(function(){
		$bookType = $(this).attr("id");
		$("#objectFilters a").removeClass("active");
		$(this).addClass("active");
		$.ajax({
    		  url: $baseUrl + "/user/booklistajax",
    		  type: 'post',
    		  dataType: 'json',
    		  async: true,
    		  data: ({'type' : $bookType, 'uid' : $("#uidHidden").text()}),
    		  success: function(data) {
			$("ul.books").hide().empty().append(data.list).slideDown("fast");
			$("#bookType").text(data.count+" "+$bookType);
    		  }});  
	});
	
	$("#available").click();
	
	$(".markAs a").live('click',function(){
		$status = $(this).attr("class");
		$bid = $(this).parents(".bookDesc").find("h2 a").attr("bid");
		$.ajax({
  		  url: $baseUrl + "/book/updatestatusajax",
  		  type: 'post',
  		  async: true,
  		  data: ({'status' : $status, 'bid' : $bid}),
  		  success: function(data) {
			$("[id='"+$status+"']").click();
  		  }}); 
	});
});